module.exports = class{
    constructor(filename){
        this.filename = filename || 'filelist.txt'
    }
    apply(compiler){
        console.log("MyPlugin运行了")
        // tap同步
        compiler.hooks.emit.tap("name", compilation=>{
            const assets = compilation.assets // 资源列表
            const fileList = []
            Object.keys(assets).forEach(key=>{
                var content = `【${key}】:大小${assets[key].size()/1000}`
                fileList.push(content)
            })

            // 添加内容
            const str = fileList.join("\n\n")
            assets[this.filename] = {
                source(){
                    return str
                },
                size(){
                    return str.length
                }
            }
            console.log("编译完成", compilation.assets)

        })
    }
}